package com.yungu.swift.api.route.v2.passenger;

import com.yungu.swift.api.base.BaseApi;
import com.yungu.swift.api.base.gateway.CurrentUser;
import com.yungu.swift.api.facade.PassengerFacade;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.api.ApiParam;
import com.yungu.swift.constants.CommonConstant;
import com.yungu.swift.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

import static com.yungu.swift.api.base.ApiErrorEnum.PARAM_ERROR;

/**
 * @author Zerrion
 */
@RestController
@RequestMapping(value = "/api/v2/passenger")
@Api(value = "【乘客】【订单】【专车】乘客专车订单接口V2", tags = "V2-乘客专车订单接口")
public class PasSpecialOrderApi extends BaseApi {

    @Autowired
    private PassengerFacade passengerFacade;

    @PostMapping(value = {"/specialOrder/listTypeTime"})
    @ApiOperation(value = "获取日租/半日租计价规则接口")
    public ResponseData<List<Map<String, Object>>> listTypeTime(@RequestBody Map<String, String> paramMap,
                                                                @CurrentUser ApiParam apiParam) {
        //车型UUID
        String carModelUuid = paramMap.get("carModelUuid");
        //区域编码
        String adCode = paramMap.get("adCode");
        if (StringUtils.isEmpty(adCode)) {
            return ResponseData.buildErrorResponse(PARAM_ERROR.getCode(), PARAM_ERROR.getMsg());
        }
        return passengerFacade.listTypeTime(adCode, carModelUuid, apiParam.getAppid(), CommonConstant.BUSINESS_TYPE_SPEC);
    }

    @PostMapping(value = {"/specialOrder/valuateRental"})
    @ApiOperation(value = "日租半日租估价接口")
    public ResponseData<Map<String, Object>> valuateRent(@RequestBody Map<String, String> paramMap,
                                                         @CurrentUser ApiParam apiParam) {
        //计价规则UUID
        String fareRuleUuid = paramMap.get("fareRuleUuid");
        if (StringUtils.isEmpty(fareRuleUuid)) {
            return ResponseData.buildErrorResponse(PARAM_ERROR.getCode(), PARAM_ERROR.getMsg());
        }
        return passengerFacade.valuateRent(apiParam.getUserUuid(), apiParam.getAppid(), fareRuleUuid);
    }


}
